//
//  OrderPayRemView.m
//  WeiYiMei
//
//  Created by iMac on 2019/4/13.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "OrderPayRemView.h"

@interface OrderPayRemView ()<UITextViewDelegate>

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UITextView *placeholderView;

@end

@implementation OrderPayRemView

- (void)setupSubViews
{
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.textColor = kColor333333;
    self.titleLab.font = [UIFont systemFontOfSize:14];
    self.titleLab.text = @"填写备注";
    [self addSubview:self.titleLab];
    
    self.inputView = [[UITextView alloc] init];
    self.inputView.font = [UIFont systemFontOfSize:14];
    self.inputView.textColor = kColor333333;
    self.inputView.backgroundColor = [UIColor clearColor];
    self.inputView.scrollEnabled = NO;
    self.inputView.delegate = self;
    self.inputView.textContainerInset = UIEdgeInsetsMake(5, 0, 5, 0);
    self.inputView.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.inputView];
    
    self.placeholderView = [[UITextView alloc] init];
    self.placeholderView.font = self.inputView.font;
    self.placeholderView.textColor = kColorAAAAAA;
    self.placeholderView.textContainerInset = self.inputView.textContainerInset;
    self.placeholderView.editable = NO;
    self.placeholderView.selectable = NO;
    self.placeholderView.scrollEnabled = NO;
    self.placeholderView.backgroundColor = [UIColor clearColor];
    self.placeholderView.text = @"请输入备注信息";
    self.placeholderView.textAlignment = self.inputView.textAlignment;
    [self addSubview:self.placeholderView];
    
    [self bringSubviewToFront:self.inputView];
}

- (void)setupConstraints
{
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(15);
    }];
    
    [self.inputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.bottom.equalTo(self).offset(-10);
        make.right.equalTo(self).offset(-15);
        make.left.equalTo(self.titleLab.mas_right).offset(20);
    }];
    
    [self.placeholderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.inputView);
    }];
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length > 0) {
        self.placeholderView.alpha = 0;
    }
    else {
        self.placeholderView.alpha = 1;
    }
}
- (void)setText:(NSString *)text
{
    _text = text;
    self.inputView.text = text;
    if (self.inputView.text.length > 0) {
        self.placeholderView.alpha = 0;
    }
    else {
        self.placeholderView.alpha = 1;
    }
}

@end
